int h1, h2, s1, b1, nLines;
int intervalColor;
boolean decreaseValue;
ArrayList <RandomLine> rLines;

void setup() {
  smooth();
  strokeWeight(3);

  // Depth of color
  intervalColor = 255;
  colorMode (HSB, intervalColor);

  // Generates the first color
  h1 = ranNum();
  s1 = round ( intervalColor / 2 );
  b1 = round ( intervalColor / 3 );

  background ( color (h1, s1, b1) ); // Default background

  generateNewColor();
  
  rLines = new ArrayList();
  nLines = round ( random (100) );
}

void draw() {
  if( decreaseValue ){
    h1--;
  }
  else{
    h1++;
  }
  
  if (h1 == h2){
    generateNewColor();
  }
  
  colorMode(HSB, intervalColor);
  background ( color (h1, s1, b1) ); // New background

  drawLines();
}

void drawLines(){
  rLines.add( new RandomLine() );
  
  nLines--;
  
  if (nLines == 0){
    rLines = new ArrayList();
    nLines = round ( random (100) );
  }
  else{
    int i;
    for (i=0; i<rLines.size(); i++){
      rLines.get(i).draw();
    }
  }
}

int ranNum() {
  return round ( random (intervalColor) );
}

void generateNewColor(){
  // Generates the second color
  h2 = ranNum();
  
  if(h2 < h1){
    decreaseValue = true;
  }
  else{
    decreaseValue = false;
  }
}
